<template>
  <div class="mod-crm__crmlabel">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <!-- <el-form-item>
        <el-input v-model="state.dataForm.id" placeholder="ID" clearable></el-input>
      </el-form-item> -->
<<<<<<< HEAD
      <!-- <el-form-item>
        <el-input v-model="state.dataForm.code" placeholder="编号" clearable></el-input>
      </el-form-item> -->
=======
      <el-form-item>
        <el-input v-model="state.dataForm.code" placeholder="编号" clearable ></el-input>
      </el-form-item>
>>>>>>> origin/s1
      <el-form-item>
        <el-input v-model="state.dataForm.titile" placeholder="标签" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.remark" placeholder="描述" clearable></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <!-- {{ state.dataForm.status }} -->
        <el-select v-model="state.dataForm.status">
          <el-option key="0" value="0">{{ $t("user.status0") }}</el-option>
          <el-option key="1" value="1">{{ $t("user.status1") }}</el-option>
        </el-select>
        <!-- <el-input v-model="state.dataForm.status" placeholder="状态" clearable></el-input> -->
        <!-- <el-radio-group v-model="state.dataForm.status">
          <el-radio :label="0">{{ $t("user.status0") }}</el-radio>
          <el-radio :label="1">{{ $t("user.status1") }}</el-radio>
        </el-radio-group> -->
      </el-form-item>
      <!-- <el-form-item>
        <el-input v-model="state.dataForm.num" placeholder="排序" clearable></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmlabel:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('crm:crmlabel:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <!-- <el-table-column prop="id" label="ID" header-align="center" align="center"></el-table-column>
      <el-table-column prop="code" label="编号" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="titile" label="标签" header-align="center" align="center"></el-table-column>
      <el-table-column prop="remark" label="描述" header-align="center" align="center"></el-table-column>
      <el-table-column prop="num" label="排序" header-align="center" align="center"></el-table-column>
      <el-table-column prop="status" label="状态" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="danger">{{ $t("user.status0") }}</el-tag>
          <el-tag v-else size="small" type="success">{{ $t("user.status1") }}</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="id" label="ID" header-align="center" align="center"></el-table-column> -->
      <!-- <el-table-column prop="code" label="编号" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="titile" label="标签" header-align="center" align="center"></el-table-column>
      <el-table-column prop="remark" label="描述" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="status" label="状态" header-align="center" align="center"></el-table-column> -->
      <!-- <el-table-column prop="num" label="排序" header-align="center" align="center"></el-table-column> -->
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('crm:crmlabel:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('crm:crmlabel:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./crmlabel-add-or-update.vue";

const view = reactive({
  getDataListURL: "/crm/crmlabel/page",
  getDataListIsPage: true,
  exportURL: "/crm/crmlabel/export",
  deleteURL: "/crm/crmlabel",
  deleteIsBatch: true,
  dataForm: {
    id: "",
    code: "",
    titile: "",
    remark: "",
    status: "",
    num: "",
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });
const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id);
  });
};
</script>